package com.liner.homework.first;

import java.util.ArrayList;
import java.util.Collection;

public class CollectionDemo {
    public static void main(String[] args) {
        //1. Collection集合基本方法的练习：add()、size()、isEmpty()、clear()、contains()、remove()
        Collection<String> c = new ArrayList<>();
        c.add("one");
        c.add("two");
        c.add("three");
        c.add("four");
        c.add("five");
        System.out.println(c);
        System.out.println("Collection的长度是:" + c.size());
        System.out.println("Collection的是否为空:" + c.isEmpty());
        System.out.println("是否包含 “six” 元素:" + c.contains("six"));
        c.remove("five");
        System.out.println("删除 “five” 元素: " + c);
        c.clear();
        System.out.println("清空Collection的所有元素: ");
        System.out.println("Collection的是否为空:" + c.isEmpty());
        //2. Collection集合间操作的练习：addAll()、containsAll()、retainAll()、removeAll()

        Collection<String> c2 = new ArrayList<>();
        c2.add("java");
        c2.add("Python");
        c2.add("C#");
        c2.add("C++");

        System.out.println("c2的集合:" + c2);
        c.addAll(c2);

        System.out.println("将c2的值添加到c中:" + c);
        c.add(".NET");
        System.out.println("给c添加元素后，判断是否包含c2:" + c.containsAll(c2));
        System.out.println("取c中保留的c2的交集:" + c.retainAll(c2));

        System.out.println("c的集合:" + c);
        System.out.println("c2的集合:" + c2);


        System.out.println("取c中保留的c2的交集:" + c.retainAll(c2));

        System.out.println("c的集合:" + c);
        System.out.println("c2的集合:" + c2);

        System.out.println("删除c中保留的c2的交集且c2不变:" + c.removeAll(c2));

        System.out.println("c的集合:" + c);
        System.out.println("c2的集合:" + c2);


    }
}
